// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.SnapshotLifecycleManagement;

public sealed partial class Retention
{
	/// <summary>
	/// <para>
	/// Time period after which a snapshot is considered expired and eligible for deletion. SLM deletes expired snapshots based on the slm.retention_schedule.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("expire_after")]
	public Elastic.Clients.Elasticsearch.Serverless.Duration ExpireAfter { get; set; }

	/// <summary>
	/// <para>
	/// Maximum number of snapshots to retain, even if the snapshots have not yet expired. If the number of snapshots in the repository exceeds this limit, the policy retains the most recent snapshots and deletes older snapshots.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("max_count")]
	public int MaxCount { get; set; }

	/// <summary>
	/// <para>
	/// Minimum number of snapshots to retain, even if the snapshots have expired.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("min_count")]
	public int MinCount { get; set; }
}

public sealed partial class RetentionDescriptor : SerializableDescriptor<RetentionDescriptor>
{
	internal RetentionDescriptor(Action<RetentionDescriptor> configure) => configure.Invoke(this);

	public RetentionDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Duration ExpireAfterValue { get; set; }
	private int MaxCountValue { get; set; }
	private int MinCountValue { get; set; }

	/// <summary>
	/// <para>
	/// Time period after which a snapshot is considered expired and eligible for deletion. SLM deletes expired snapshots based on the slm.retention_schedule.
	/// </para>
	/// </summary>
	public RetentionDescriptor ExpireAfter(Elastic.Clients.Elasticsearch.Serverless.Duration expireAfter)
	{
		ExpireAfterValue = expireAfter;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Maximum number of snapshots to retain, even if the snapshots have not yet expired. If the number of snapshots in the repository exceeds this limit, the policy retains the most recent snapshots and deletes older snapshots.
	/// </para>
	/// </summary>
	public RetentionDescriptor MaxCount(int maxCount)
	{
		MaxCountValue = maxCount;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Minimum number of snapshots to retain, even if the snapshots have expired.
	/// </para>
	/// </summary>
	public RetentionDescriptor MinCount(int minCount)
	{
		MinCountValue = minCount;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("expire_after");
		JsonSerializer.Serialize(writer, ExpireAfterValue, options);
		writer.WritePropertyName("max_count");
		writer.WriteNumberValue(MaxCountValue);
		writer.WritePropertyName("min_count");
		writer.WriteNumberValue(MinCountValue);
		writer.WriteEndObject();
	}
}